package com.example.leave.infrastructure.mapper;

import com.example.leave.api.vo.ApprovalVo;
import com.example.leave.application.client.InfrastructureClient;
import com.example.leave.application.client.dto.PersonDto;
import com.example.leave.domain.leave.aggregate.Leave;
import com.example.leave.domain.leave.aggregate.valueObject.Approver;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * TODO
 *
 * @author lxh
 * @date 2020/11/25 下午2:59
 **/
@Mapper(componentModel = "spring")
public abstract class LeaveMapper {
    @Autowired
    private InfrastructureClient infrastructureClient;

    @Mapping(source = "applicantId", target = "applicant.personId")
    @Mapping(source = "approverId", target = "approver")
    public abstract Leave toLeave(ApprovalVo approvalVo);

    public abstract Approver toApprover(PersonDto personDto);

    public Approver toApprover(String approverId) {
        return toApprover(infrastructureClient.findPersonById(approverId));
    }
}
